% Lucia Wagner and Sara Clifton- September 2021
% code to generate Figure 2

% load adult data
load("smoking_data_copy.mat");
data1 = smokingUSCopy;

d1 = data1((91:100),2); %smoking              
d2 = data1((91:100),3); %vaping

% load youth data
load("YouthSmokingData_copy.mat");
data2 = YouthSmokingDataCopy;

d3 = data2([14 16 18 20 21 22],2); %smoking
d4 = data2([14 16 18 20 21 22],3); %vaping

% generate figure
figure
t=tiledlayout(1,2);
p1=nexttile;
bar([d1(:) d2(:)], 'Stacked','BarWidth',0.7)
legend({'Smoking', 'Vaping'},'Location',"northwest")
set(gca,'XTickLabel',{'2010','2011','2012','2013','2014','2015','2016','2017','2018','2019'})
set(gca,'XTickLabelRotation',45)
set(gca,'FontSize',14)
ylim([0 0.35])
title(p1,'Adult')
x0=10;
y0=8;
width=550;
height=320;
set(gcf,'position',[x0,y0,width,height])
p2=nexttile;
bar([d3(:) d4(:)], 'Stacked','BarWidth',0.7)
legend({'Smoking', 'Vaping'},'Location','northwest')
set(gca,'XTickLabel',{'2011','2013','2015','2017','2018','2019'})
set(gca,'XTickLabelRotation',45)
set(gca,'FontSize',14)
set(gca,'Yticklabel',[])
ylim([0 0.35])
title(p2,'Youth')
x0=10;
y0=8;
width=550;
height=320;
set(gcf,'position',[x0,y0,width,height])
t.Padding = 'compact';
t.TileSpacing = 'tight';
linkaxes([p1,p2],'y');
xlabel(t,'Year','FontSize',14)
ylabel(t,'Prevalence','FontSize',14)